package com.cangmaomao.m_mePen.presenter

import com.cangmaomao.m_mePen.bean.FileListBean
import com.cangmaomao.m_mePen.contract.FileListContract
import java.io.File

class FileListPresenter(val view: FileListContract.View) : FileListContract.Presenter {


    init {
        view.setPresenter(this)
    }

    override fun start() {
        readFiles()
    }


    override fun readFiles() {
        val files = view.readLocalFile()
        if (!files.isEmpty()) {
            val list = mutableListOf<FileListBean>()
            files.forEach {
                val lastList = it.listFiles()
                var size = 0
                lastList.forEach {
                    size = it.listFiles().size
                }
                list.add(FileListBean(it.name, size, it.path))
            }
            view.showLocalFile(list)
        }
    }


}